package com.example.tcpandroidclient;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {
	Button start;
	TextView ausgabe;
	//Thread m_objThreadClient;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		start = (Button) findViewById(R.id.start);
		ausgabe = (TextView) findViewById(R.id.ausgabe);

	}

	public void start(View view) {
		// m_objThreadClient = new Thread(new Runnable() {
			
				ausgabe.setText("Runnable!!!");

				try {
					//@Home
					//InetAddress serverAddr = InetAddress.getByName("192.168.1.33");
					//@Hochschule
					InetAddress serverAddr = InetAddress.getByName("10.10.14.50");

					//Log.d("TCP", "C: Connecting...");
					// ServerSocket mit IP und Port wird erstellt
					Socket socket = new Socket(serverAddr, 12345);

					String message = "Hallo ich bin der Client und wir sind verbunden";
					try {

					//	Log.d("TCP", "C: Sending: '" + message + "'");

						PrintWriter out = new PrintWriter(
								new BufferedWriter(new OutputStreamWriter(
										socket.getOutputStream())), true);

						out.println(message);

						//Log.d("TCP", "C: Sent.");

						//Log.d("TCP", "C: Done.");

					} catch (Exception e) {

						Log.e("TCP", "S: Error", e);
					} finally {

						socket.close();

					}
				} catch (Exception e) {

					Log.e("TCP", "C: Error", e);

				}

			}

		//});
		//m_objThreadClient.start();

	}


